package org.linuxsogood.boot.zk;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author honway.liu
 * @date 2019-07-06 17:52
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class ZookeeperConnector implements Watcher {
    public static void main(String[] args) throws IOException, InterruptedException {
        String connectString = "127.0.0.1:2181";
        int timeouot = 1000;
        ZooKeeper zooKeeper = new ZooKeeper(connectString, timeouot, new ZookeeperConnector());
        System.out.println(zooKeeper.getState());
        TimeUnit.SECONDS.sleep(2);
        System.out.println("end");
    }

    @Override
    public void process(WatchedEvent watchedEvent) {
        System.out.println("接收到事件: "+ watchedEvent);
    }
}
